* Set current directory and open log
cd "E:\Seagate Sync\VOL\Personal folder\Documents\Research\Current projects\Working party meetings\Posted\EUP 160404"
capture log close
log using "Data management\wpar-management01-separate", replace text


*************************************************************************************
* Distinguish Council, Coreper, and working party meetings to process them separately
*************************************************************************************


* Project and author information
********************************
* Programme:	wpar-management01-separate.do
* Date:			4 April 2016
* Author:		Frank Haege, University of Limerick
* Contact:		frank.haege@ul.ie 

* Do-file description
*********************
* The meeting dates for the last period (2011 to 2014) were supplied in a single Excel file, including meetings of 
* all different types of bodies. The do-file separates Council, Coreper, and working party
* meetings and merges them with already existing datasets of pre-2011 meetings of the respective bodies. 


* Clear memory  
**************
version 12.0
clear all
macro drop _all
set more off

* Load dataset with information on dates and duration of working party meetings
insheet using "Input data\wpar-rawdata-all-2011-2014.csv", clear comma names
des

* Name EEAS variable
rename v7 eeas

* Describe data set
describe, d

* Sort by meeting description
sort meetingdescription sessiondate slots

* Generate Coreper variable
table meetingdescription if regexm(meetingdescription, "(COREPER)|(Coreper)")
generate coreper = 0
replace coreper = 1 if regexm(meetingdescription, "(COREPER)|(Coreper)")
table coreper, m

* Generate Council variable
groups meetingdescription if regexm(meetingdescription, "(CONSEIL )|(Conseil )"), order(h) miss
generate council = 0
replace council = 1 if regexm(meetingdescription, "(CONSEIL )|(Conseil )")
groups council, order(h) miss
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL EUROPEEN"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL EUROPEEN")
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL( DE)? COOP"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL( DE)? COOP")
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL DE L'EUROPE"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL DE L'EUROPE")
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL( DE)? STAB"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL( DE)? STAB")
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL D'ASSOC"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL D'ASSOC")
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL CONJ"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL CONJ")
groups meetingdescription if council == 1 & regexm(meetingdescription, "CONSEIL SUR CHYPRE"), order(h) miss
replace council = 0 if council == 1 & regexm(meetingdescription, "CONSEIL SUR CHYPRE")
groups meetingdescription if regexm(meetingdescription, "MINISTRES COMMERCE"), order(h) miss
replace council = 1 if regexm(meetingdescription, "MINISTRES COMMERCE")
groups meetingdescription if regexm(meetingdescription, "MINISTRES DEFENSE"), order(h) miss
replace council = 1 if regexm(meetingdescription, "MINISTRES DEFENSE")
replace council = 0 if meetingdescription == "RESERVEE DEBRIEF. MINISTRES DEFENSE"
replace council = 0 if meetingdescription == "BRIEFING CONSEIL EDUCATION, JEUNESSE ET CULTURE"
table council, m

* Check coding
groups meetingdescription if coreper == 1, order(h)
groups meetingdescription if council == 1, order(h)

* Save Coreper data separately and append to data of earlier period
preserve
keep if coreper == 1
drop eeas coreper council
des
save "Input data\wpar-rawdata-coreper-2011-2014.dta", replace
use "Input data\wpar-rawdata-coreper-1996-2010.dta", clear
append using "Input data\wpar-rawdata-coreper-2011-2014.dta"
des
save "Input data\wpar-rawdata-coreper-1996-2014.dta", replace
restore

* Save Council data separately and append to data of earlier period
preserve
keep if council == 1
drop eeas coreper council
des
save "Input data\wpar-rawdata-council-2011-2014.dta", replace
use "Input data\wpar-rawdata-council-1996-2010.dta", clear
append using "Input data\wpar-rawdata-council-2011-2014.dta"
des
save "Input data\wpar-rawdata-council-1996-2014.dta", replace
restore

* Save working party data separately and append to data of earlier period
keep if council == 0 & coreper == 0
drop eeas coreper council
rename meetingdescription wpname
rename sessiondate date
des
save "Input data\wpar-rawdata-workingparties-2011-2014.dta", replace
use "Input data\wpar-rawdata-workingparties-1995-2010.dta", clear
append using "Input data\wpar-rawdata-workingparties-2011-2014.dta"
des
save "Input data\wpar-rawdata-workingparties-1995-2014.dta", replace

